<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<meta name="description" content="">
		<meta name="author" content="">
		<title>个人博客系统-登录</title>
		<script src="js/jquery.js"></script>
		<link href="blog/source/asserts/css/bootstrap.min.css" rel="stylesheet">
		<link href="blog/source/asserts/css/signin.css" rel="stylesheet">
		<script src="js/vue.js"></script>
		<script src="js/axios.min.js"></script>
	</head>
	<body class="text-center">
		<div id="app">
			<img class="mb-4" src="blog/source/asserts/img/bootstrap-solid.svg" alt="" width="72" height="72">
			<h1 class="h3 mb-3 font-weight-normal">请登录</h1>
			<!--判断-->
			<label class="sr-only" >用户名：</label>
			<input type="text" v-model="blogger.username" class="form-control" placeholder="Username" style="width: 250px">
			<label class="sr-only" >密码</label>
			<input type="password" v-model="blogger.password" class="form-control" placeholder="Password">

			<button class="btn btn-lg btn-primary btn-block" type="submit" @click="signIn">登录</button>
			<p class="mt-5 mb-3 text-muted">© 2020-2021</p>
		</div>
	</body>
	<script>
		$(function () {
			var vm = new Vue({
				el:"#app",
				data:{
					blogger:{}//博主表
				},
				methods:{
					//博主登录
					signIn() {
						if(this.blogger.username == null || this.blogger.username.length == 0){
							alert("请输入账号!");
							return;
						}else if(this.blogger.password == null || this.blogger.username.password == 0){
							alert("请输入密码!");
							return;
						}else {
							axios.defaults.withCredentials = true;
							axios.post("http://localhost:8081/kun/admin/blogger/signIn",this.blogger).then(res=>{
								var data = res.data;
								if(data.code == 200){
									sessionStorage.setItem("blogger",JSON.stringify(data.data.blogger));//转换为JSON字符串
									location.href = "blog/admin/index.html";
								}else {
									alert(data.message);
									location.href = "login.html";
								}
							});
						}
					}
				}
			})
		});
	</script>
</html>